#include "dosVisualize.hpp"
#include "../Algorithm/navigation.hpp"
#include <unistd.h>

int main()
{
    string filepath = "../maps/21.map";
    MainProcess mainp(filepath);

    char movement;
    int x, y;
    Navigator navigator;
    string attachText;
    vector<Point2D> empty;

    cout << "Program start!" << endl;
    while (1)
    {
        attachText = "Please input target location by 'x y'";
        // 显示并获取输入
        showState(mainp.state, attachText, 1, 0);
        cin >> x;
        cin >> y;

        // 获取路径
        cout << "get input " << x << "," << y << endl;
        cout << "Start to get the path ... ..." << endl;
        navigator.init(mainp.state.map,empty);
        vector<Point2D> path = navigator.navigate(mainp.state.man, {x, y});
        string pathText = navigator.path2cmd(path);

        if (path.size() == 0)
        {
            cout << "fail to get the path to " << x << "," << y << "!!!!" << endl;
            cout << "press any key to continue ... ..." << endl;
            continue;
        }

        cout << "I have get the path, it take " << path.size() << " step to reach." << endl;
        cout << "Path = " << pathText << endl;
        cout << "press 'y' to activate ... ..." << endl;
        // cin >> movement;
        // if (movement != 'y')
        //     continue;
        // 按照路径移动
        attachText = "Navigating ... ...";
        for (int i = 0; i < pathText.size(); i++)
        {
            mainp.MoveToward(pathText[i]);
            showState(mainp.state, attachText, 1, 0);
            usleep(100000);
        }
    }
    showState(mainp.state, attachText, true, false);
    cout << "Program end!" << endl;
    return 0;
}